package com.guo.util;

import java.io.Serializable;
import java.util.List;

/**
 * @Auther Heart Guo
 * @Date 2022/03/08-10:15
 */
public class MsgBaseRtn<T> implements Serializable {

    private static final long serialVersionUID = 1l;

    /**
     * 详情
     */
    private String detail;

    /**
     * 结果
     */
    private String msg = "success";

    /**
     * 错误代码
     */
    private String errorCode;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 总条数
     */
    private Long count;

    private T obj;

    private List<T> listData;

    public void success(){
        this.errorCode = "0000";
        if(null == this.errorMessage || "".equals(this.errorMessage)){
            this.errorMessage = "success";
        }
    }

    public MsgBaseRtn<T> failure(String errorCode,String errorMessage){
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
        return this;
    }

    public MsgBaseRtn<T> ok(){
        this.errorCode = "0000";
        this.errorMessage = "成功";
        return this;
    }

    public MsgBaseRtn<T> ok(T obj){
        this.errorMessage = "成功";
        this.errorCode = "0000";
        this.obj = obj;
        return this;
    }

    public static MsgBaseRtn instance(){
        MsgBaseRtn msgBaseRtn = new MsgBaseRtn();
        return msgBaseRtn.ok();
    }

    public MsgBaseRtn<T> code(String code){
        this.errorCode = code;
        return this;
    }

    public MsgBaseRtn<T> message(String message){
        this.errorMessage = message;
        return this;
    }

    public MsgBaseRtn<T> data(T data){
        this.obj = data;
        return this;
    }

    public MsgBaseRtn<T> list(List<T> list){
        this.errorMessage = "成功";
        this.errorCode = "0000";
        this.listData = list;
        return this;
    }

    public MsgBaseRtn<T> count(Long count){
        this.count = count;
        return this;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public List<T> getListData() {
        return listData;
    }

    public void setListData(List<T> listData) {
        this.listData = listData;
    }
}
